home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / vv.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  4KB  |  189 lines

  1. /* --------------------------------- vv.c ----------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Velocity Vector (Flight Path Marker) stuff.
  8. */
  9.  
  10. #include "plane.h"
  11.  
  12.  
  13. extern int FAR
  14. get_vv (OBJECT *p, VECT RR)
  15. {
  16.     int    tt;
  17.  
  18.     Vcopy (RR, EX->v);
  19.     if (EX->hud3 & HUD_GVV) {
  20.         tt = fmul (RR[X], p->cosy);
  21.         RR[X] += fmul (tt, p->cosy);
  22.         RR[Z] += fmul (tt, p->siny);
  23.     } else
  24.         tt = 0;
  25.     return (tt);
  26. }
  27.  
  28. LOCAL_FUNC void NEAR
  29. do_fpm (HUD *h, int VV[2], int rx, int ry, int tx, int ty, int color, int ret,
  30.     int type)
  31. {
  32.     if (VV[Y] > h->clipt-ty) {
  33.         VV[Y] = h->clipt-ty;
  34.         ret = 1;
  35.     }
  36.     if (1 == ret && (Uint)st.present % 250 > 125)    /* blink rate: 4Hz */
  37.         return;
  38.  
  39.     show_fpm (h->orgx + VV[X], h->orgy - VV[Y], rx, ry, tx, ty,
  40.         color, type);
  41. }
  42.  
  43. /* Show the flight path marker and (optionally) the flight director.
  44. */
  45. extern void FAR
  46. show_vv (HUD *h, VIEW *view, OBJECT *p, int color)
  47. {
  48.     int    x, y, tx, ty, rx, ry, type, ret;
  49.     int    sa, ca;
  50.     ANGLE    a;
  51.     VECT    RR;
  52.     int    VV[2];
  53.  
  54.     if (!(EX->hud & HUD_VV) && !(EX->hud2 & HUD_DIRECTOR)) {
  55.         VVDELAY = 0;
  56.         return;
  57.     }
  58.  
  59.     rx = fmul (h->sx, RVV);
  60.     ry = fmul (h->sy, RVV);
  61.  
  62.     type = EX->hud1 & HUD_TYPES;
  63.     if (type == HUD_F16) {
  64.         tx = fmul (h->sx, EX->ldgap);
  65.         ty = ry*2;
  66.     } else if (type == HUD_F15) {
  67.         tx = rx*2;
  68.         ty = ry*2;
  69.     } else {
  70.         tx = fmul (h->sx, SVV);
  71.         ty = fmul (h->sy, SVV*4/5);
  72.     }
  73.  
  74. /* Show caged vv (optional).
  75. */
  76.     if (p->speed <= 4*VONE || !(EX->hud3 & HUD_GVV))
  77.         goto no_cvv;
  78.  
  79.     ca = get_vv (p, RR);
  80.     a = ATAN (ca, RR[Y]);
  81.  
  82.     screen_coords (view, RR);
  83.     ret = clip_to_screen (h->VV, RR, h->maxx, h->maxy,
  84.             h->clipx-tx, h->clipy-ry, h->shifty);
  85.     if (2 == ret)
  86.         goto no_cvv;
  87.  
  88.     do_fpm (h, h->VV, rx, ry, tx, ty, color, ret,
  89.         1 + (type != HUD_CLASSIC));
  90.  
  91.     if (iabs(a) < DEG(1))
  92.         goto only_cvv;
  93. no_cvv:
  94.  
  95. /* Show true vv.
  96. */
  97.     if (p->speed > 4*VONE) {
  98.         Vcopy (RR, EX->v);
  99.         screen_coords (view, RR);
  100.         ret = clip_to_screen (VV, RR, h->maxx, h->maxy,
  101.                 h->clipx-tx, h->clipy-ry, h->shifty);
  102.         if (2 == ret)
  103.             goto no_vv;
  104.     } else {
  105.         VV[X] = VV[Y] = 0;
  106.         ret = 0;
  107.     }
  108.  
  109.     do_fpm (h, VV, rx, ry, tx, ty, color, ret,
  110.         (EX->hud3 & HUD_GVV) ? 0 : 1 + (type != HUD_CLASSIC));
  111.  
  112. no_vv:
  113.     if (!(EX->hud3 & HUD_GVV)) {
  114.         h->VV[X] = VV[X];
  115.         h->VV[Y] = VV[Y];
  116.     }
  117. only_cvv:
  118.  
  119.     if (EX->hud2 & HUD_VW) {
  120.         if (ret) {
  121.             if ((VVDELAY += st.interval) > VVPERIOD)
  122.                 VVDELAY = VVPERIOD;
  123.         } else if (VVDELAY > 0) {
  124.             if ((VVDELAY -= st.interval) < 0)
  125.                 VVDELAY = 0;
  126.         }
  127.     } else
  128.         VVDELAY = 0;
  129.  
  130.     if ((EX->hud2 & HUD_DIRECTOR) &&
  131.         (EX->misc[12] || EX->misc[13])) {
  132.         x = rx;
  133.         rx = tx;
  134.         tx = x*8;
  135.  
  136.         y = ry;
  137.         ry = ty;
  138.         ty = y*8;
  139.  
  140.         sa = SIN(EX->misc[13]);        /* roll */
  141.         ca = COS(EX->misc[13]);
  142.  
  143.         y = EX->misc[12];        /* pitch */
  144.         if (y > DEG(30))
  145.             y = DEG(30);
  146.         else if (y < -DEG(30))
  147.             y = -DEG(30);
  148.         x = muldiv (h->sx/2, y, DEG(30));
  149.         y = muldiv (h->sy/2, y, DEG(30));
  150.         x = fmul (x, sa);
  151.         y = fmul (y, ca);
  152.  
  153.         x += h->VV[X];
  154.         y += h->VV[Y];
  155. #if 0
  156.         if (x > h->clipr-tx)
  157.             x = h->clipr-tx;
  158.         else if (x < h->clipl+tx)
  159.             x = h->clipl+tx;
  160.         if (y > h->clipt-ty)
  161.             y = h->clipt-ty;
  162.         else if (y < h->clipb+ty)
  163.             y = h->clipb+ty;
  164. #endif
  165.         x = h->orgx + x;
  166.         y = h->orgy - y;
  167.         show_dir1 (x, y, rx, ry, tx, ty, sa, ca, h->fgi,
  168.             h->orgx, h->orgy, h->sx, h->sy, h->shifty);
  169.     }
  170. }
  171.  
  172. /* Show the waterline mark.
  173. */
  174. extern void FAR
  175. show_wl (HUD *h, OBJECT *p, int color)
  176. {
  177.     int    tx, ty;
  178.  
  179.     if (EX->hud & HUD_PLUS)
  180.         return;
  181.  
  182.     if (VVDELAY > 0 ||
  183.         ((HUD_FA18 == (EX->hud1 & HUD_TYPES)) && (EX->equip & EQ_GEAR))) {
  184.         tx = fmul (h->sx, SVV);
  185.         ty = fmul (h->sy, SVV);
  186.         show_w (h->orgx, h->orgy, tx, ty, color);
  187.     }
  188. }
  189.